Skip to content

Conversation

@paulRbr
Copy link

@paulRbr paulRbr commented Nov 25, 2025

This commit removes the checks on the meilisearch conditions options :if and :unless in the ms_must_reindex? method as they are incorrectly used.

Low level reason

Indeed the README documents an example on how to avoid reindexing when an if: condition is defined (e.g. if: :published?). However the documented way doesn't work: Indeed, one would need to define a method #will_save_change_to_published?? (note the two question marks) to be able to prevent reindexing. However ruby doesn't allow such a method name (with double trailing question marks).

Higher level reason

In a high level vision, the if: and unless: conditions are used as “constraints” when the lib will try to index a resource in many different places of the code by executing Utilities.indexable?(...) before trying to index, those those conditions are sufficient to “enable” or “disable” the indexation of the lib, no matter what attributes change on the record.

Why would the “must_reindex” logic try to check those conditions? I admit I didn't understand and believe this code is obsolete.

What do you folks think?

Pull Request

Related issue

Fixes #<issue_number>

What does this PR do?

  • ...

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • Refactor
    • Removed conditional reindexing options (:if and :unless), eliminating complex conditional evaluation logic.
    • Reindexing now occurs exclusively when primary keys or tracked attributes change.
    • Simplifies the reindexing mechanism and reduces unnecessary database operations.

✏️ Tip: You can customize this high-level summary in your review settings.

This commit removes the checks on the meilisearch conditions options `:if` and `:unless` in the `ms_must_reindex?` method as they are incorrectly used.

## Low level reason

[Indeed the README documents an example on how to avoid reindexing when an `if:` condition is defined (e.g. `if: :published?`)](https://github.com/meilisearch/meilisearch-rails/tree/main?tab=readme-ov-file#conditional-indexing). However the documented way doesn't work: Indeed, one would need to define a method `#will_save_change_to_published??` (note the two question marks) to be able to prevent reindexing. However ruby doesn't allow such a method name (with double trailing question marks).

## Higher level reason

In a high level vision, the `if:` and `unless:` conditions are used as “constraints” when the lib will try to index a resource in many different places of the code by executing `Utilities.indexable?(...)` before trying to index, those those conditions are sufficient to “enable” or “disable” the indexation of the lib, no matter what attributes change on the record.

Why would the “must_reindex” logic try to check those conditions? I admit I didn't understand and believe this code is obsolete.

What do you folks think?
@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

Walkthrough

The ms_must_reindex? method in lib/meilisearch-rails.rb is simplified by removing conditional reindexing logic that previously evaluated :if and :unless options. The method now only checks for primary key and attribute changes.

Changes

Cohort / File(s) Change Summary
Conditional Reindexing Logic Removal
lib/meilisearch-rails.rb
Removed evaluation of :if and :unless options from ms_must_reindex? method; the method now only checks primary key and attribute changes, simplifying control flow and removing early conditional returns.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant ms_must_reindex
    
    rect rgb(240, 248, 255)
    Note over Caller,ms_must_reindex: Before: With Conditional Logic
    Caller->>ms_must_reindex: Call with options {:if, :unless}
    ms_must_reindex->>ms_must_reindex: Evaluate :if option
    ms_must_reindex->>ms_must_reindex: Evaluate :unless option
    ms_must_reindex-->>Caller: Return boolean (conditional-based)
    end
    
    rect rgb(248, 240, 255)
    Note over Caller,ms_must_reindex: After: Simplified Logic
    Caller->>ms_must_reindex: Call
    ms_must_reindex->>ms_must_reindex: Check primary key changes
    ms_must_reindex->>ms_must_reindex: Check attribute changes
    ms_must_reindex-->>Caller: Return boolean (changes-based only)
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Behavioral impact: Verify that removal of :if and :unless conditional evaluation doesn't break existing reindexing workflows or integrations that relied on these options.
  • Test coverage: Ensure tests validate that the method still correctly detects primary key and attribute changes after the simplification.

Poem

🐰 A rabbit hops through cleaner code today,
Conditions gone, the logic's sleek and light,
No more :if and :unless in the way,
Just changes checked—pure simplicity in sight!
Reindex swift, no branching left to play.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the primary change: removal of conditional logic checks from the ms_must_reindex? method, which aligns with the actual code modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16e4d4b and eca701e.

📒 Files selected for processing (1)
  • lib/meilisearch-rails.rb (0 hunks)
💤 Files with no reviewable changes (1)
  • lib/meilisearch-rails.rb

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@paulRbr
Copy link
Author

paulRbr commented Nov 25, 2025

The ms_must_reindex? method in lib/meilisearch-rails.rb is simplified by removing conditional reindexing logic that previously evaluated :if and :unless options.

This is not true. The previous code didn't “evaluate” the :if and :unless conditions, it called ms_attribute_changed?(record, condition) method on a condition name (e.g. :published?) which has nothing to do with an attribute name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant